<template>
  <div class="create-post-view">
    <!-- 页面头部 -->
    <div class="page-header">
      <div class="header-content">
        <div class="breadcrumb">
          <router-link to="/forum" class="breadcrumb-link">论坛</router-link>
          <span class="breadcrumb-separator">/</span>
          <span class="breadcrumb-current">发布帖子</span>
        </div>
        <h1 class="page-title">发布新帖子</h1>
        <p class="page-subtitle">分享你的公考经验，帮助更多考生备考</p>
      </div>
    </div>

    <!-- 发布表单 -->
    <div class="create-post-container">
      <div class="post-form-card">
        <div class="form-header">
          <h2 class="form-title">
            <el-icon><Edit /></el-icon>
            填写帖子信息
          </h2>
          <div class="form-tips">
            <el-icon><InfoFilled /></el-icon>
            <span>请认真填写，优质内容更容易获得关注</span>
          </div>
        </div>

        <el-form 
          ref="postFormRef"
          :model="postForm" 
          :rules="postRules"
          label-width="0"
          class="post-form"
        >
          <!-- 分类选择 -->
          <div class="form-section">
            <div class="section-header">
              <h3 class="section-title">选择分类</h3>
              <span class="required-mark">*</span>
            </div>
            <div class="category-grid">
              <div 
                v-for="category in categories" 
                :key="category.id"
                class="category-item"
                :class="{ 'selected': postForm.categoryId === category.id }"
                @click="selectCategory(category.id)"
              >
                <div class="category-icon">
                  <el-icon><component :is="getCategoryIcon(category.name)" /></el-icon>
                </div>
                <div class="category-info">
                  <h4 class="category-name">{{ category.name }}</h4>
                  <p class="category-desc">{{ getCategoryDescription(category.name) }}</p>
                </div>
                <div class="category-check">
                  <el-icon v-if="postForm.categoryId === category.id"><Check /></el-icon>
                </div>
              </div>
            </div>
          </div>

          <!-- 文档编辑器区域 -->
          <div class="document-editor">
            <div class="editor-toolbar">
              <div class="toolbar-group">
                <el-button-group>
                  <el-button size="small" @click="insertText('**', '**')" title="粗体">
                    <el-icon><Star /></el-icon>
                  </el-button>
                  <el-button size="small" @click="insertText('*', '*')" title="斜体">
                    <el-icon><Star /></el-icon>
                  </el-button>
                  <el-button size="small" @click="insertText('`', '`')" title="代码">
                    <el-icon><Star /></el-icon>
                  </el-button>
                </el-button-group>
              </div>
              <div class="toolbar-group">
                <el-button size="small" @click="insertText('\n- ', '')" title="无序列表">
                  <el-icon><List /></el-icon>
                </el-button>
                <el-button size="small" @click="insertText('\n1. ', '')" title="有序列表">
                  <el-icon><List /></el-icon>
                </el-button>
              </div>
              <div class="toolbar-group">
                <el-button size="small" @click="insertText('\n> ', '')" title="引用">
                  <el-icon><Star /></el-icon>
                </el-button>
                <el-button size="small" @click="insertText('\n---\n', '')" title="分割线">
                  <el-icon><Minus /></el-icon>
                </el-button>
              </div>
              <div class="toolbar-group">
                <el-button size="small" @click="insertText('# ', '')" title="一级标题">
                  H1
                </el-button>
                <el-button size="small" @click="insertText('## ', '')" title="二级标题">
                  H2
                </el-button>
              </div>
            </div>
            
            <div class="editor-content-wrapper">
              <el-form-item prop="title" class="title-form-item">
                <el-input
                  v-model="postForm.title"
                  placeholder="请输入标题..."
                  maxlength="100"
                  class="document-title-input"
                  @input="onTitleInput"
                />
              </el-form-item>
              
              <el-form-item prop="content" class="content-form-item">
                <el-input
                  v-model="postForm.content"
                  type="textarea"
                  :rows="20"
                  placeholder="开始写作..."
                  class="document-content-textarea"
                  @input="onContentInput"
                />
              </el-form-item>
              
              <div class="editor-footer">
                <div class="char-count">
                  {{ postForm.content.length }} / 5000 字符
                </div>
                <div class="editor-tips">
                  <el-icon><InfoFilled /></el-icon>
                  <span>支持 Markdown 格式，详细的内容更容易获得回复</span>
                </div>
              </div>
            </div>
          </div>

          <!-- 标签选择 -->
          <div class="form-section">
            <div class="section-header">
              <h3 class="section-title">添加标签</h3>
              <span class="optional-mark">可选</span>
            </div>
            <div class="tags-container">
              <div class="tag-input">
                <el-input
                  v-model="newTag"
                  placeholder="输入标签名称..."
                  size="small"
                  @keyup.enter="addTag"
                  class="tag-input-field"
                />
                <el-button type="primary" size="small" @click="addTag" :disabled="!newTag.trim()">
                  添加
                </el-button>
              </div>
              <div class="tag-suggestions">
                <span class="suggestion-label">推荐标签：</span>
                <el-tag
                  v-for="tag in suggestedTags"
                  :key="tag"
                  size="small"
                  class="suggestion-tag"
                  @click="addSuggestedTag(tag)"
                >
                  {{ tag }}
                </el-tag>
              </div>
              <div class="selected-tags" v-if="postForm.tags.length > 0">
                <el-tag
                  v-for="(tag, index) in postForm.tags"
                  :key="index"
                  closable
                  @close="removeTag(index)"
                  class="selected-tag"
                >
                  {{ tag }}
                </el-tag>
              </div>
            </div>
          </div>

          <!-- 发布设置 -->
          <div class="form-section">
            <div class="section-header">
              <h3 class="section-title">发布设置</h3>
            </div>
            <div class="publish-settings">
              <el-checkbox v-model="postForm.isAnonymous" class="setting-item">
                匿名发布
              </el-checkbox>
              <el-checkbox v-model="postForm.allowComments" class="setting-item">
                允许评论
              </el-checkbox>
              <el-checkbox v-model="postForm.notifyFollowers" class="setting-item">
                通知关注者
              </el-checkbox>
            </div>
          </div>

          <!-- 操作按钮 -->
          <div class="form-actions">
            <div class="action-buttons">
              <el-button size="large" @click="saveDraft" :loading="isSavingDraft">
                <el-icon><Document /></el-icon>
                保存草稿
              </el-button>
              <el-button size="large" @click="previewPost">
                <el-icon><View /></el-icon>
                预览
              </el-button>
              <el-button 
                type="primary" 
                size="large" 
                @click="submitPost"
                :loading="isSubmitting"
                class="submit-btn"
              >
                <el-icon><Check /></el-icon>
                发布帖子
              </el-button>
            </div>
            <div class="action-tips">
              <el-icon><InfoFilled /></el-icon>
              <span>发布前请仔细检查内容，发布后24小时内可以编辑</span>
            </div>
          </div>
        </el-form>
      </div>

      <!-- 右侧帮助信息 -->
      <div class="help-sidebar">
        <div class="help-card">
          <h3 class="help-title">
            <el-icon><QuestionFilled /></el-icon>
            发帖指南
          </h3>
          <div class="help-content">
            <div class="help-item">
              <h4>标题建议</h4>
              <ul>
                <li>简洁明了，突出核心问题</li>
                <li>避免使用"求助"、"急"等词汇</li>
                <li>包含具体的关键词</li>
              </ul>
            </div>
            <div class="help-item">
              <h4>内容建议</h4>
              <ul>
                <li>详细描述问题背景</li>
                <li>提供具体的信息和数据</li>
                <li>使用清晰的段落结构</li>
              </ul>
            </div>
            <div class="help-item">
              <h4>标签建议</h4>
              <ul>
                <li>选择相关的专业标签</li>
                <li>避免使用过于宽泛的标签</li>
                <li>建议使用3-5个标签</li>
              </ul>
            </div>
          </div>
        </div>

        <div class="help-card">
          <h3 class="help-title">
            <el-icon><Star /></el-icon>
            热门话题
          </h3>
          <div class="trending-topics">
            <el-tag 
              v-for="topic in trendingTopics" 
              :key="topic"
              size="small"
              class="topic-tag"
              @click="insertTopic(topic)"
            >
              {{ topic }}
            </el-tag>
          </div>
        </div>
      </div>
    </div>

    <!-- 预览模态框 -->
    <el-dialog
      v-model="showPreview"
      title="帖子预览"
      width="80%"
      :before-close="closePreview"
    >
      <div class="preview-content">
        <h2 class="preview-title">{{ postForm.title }}</h2>
        <div class="preview-meta">
          <span class="preview-category">{{ getCategoryName(postForm.categoryId) }}</span>
          <span class="preview-tags">
            <el-tag v-for="tag in postForm.tags" :key="tag" size="small">{{ tag }}</el-tag>
          </span>
        </div>
        <div class="preview-body" v-html="formatContent(postForm.content)"></div>
      </div>
      <template #footer>
        <el-button @click="closePreview">关闭预览</el-button>
        <el-button type="primary" @click="submitPost" :loading="isSubmitting">
          确认发布
        </el-button>
      </template>
    </el-dialog>
  </div>
</template>

<script setup lang="ts">
import { ref, reactive, onMounted } from 'vue'
import { useRouter } from 'vue-router'
import { ElMessage } from 'element-plus'
import { 
  Edit, InfoFilled, Check, List, Minus, Document, View, QuestionFilled, Star,
  Reading, Trophy, ChatDotSquare, User
} from '@element-plus/icons-vue'
import { createPost } from '@/api/forum'
import { useUserStore } from '@/store/user'

const router = useRouter()
const userStore = useUserStore()

// 表单数据
const postForm = reactive({
  categoryId: '',
  title: '',
  content: '',
  tags: [] as string[],
  isAnonymous: false,
  allowComments: true,
  notifyFollowers: true
})

// 表单验证规则
const postRules = {
  title: [
    { required: true, message: '请输入帖子标题', trigger: 'blur' },
    { min: 5, max: 100, message: '标题长度应在5-100个字符之间', trigger: 'blur' }
  ],
  content: [
    { required: true, message: '请输入帖子内容', trigger: 'blur' },
    { min: 10, max: 5000, message: '内容长度应在10-5000个字符之间', trigger: 'blur' }
  ]
}

// 状态
const postFormRef = ref()
const isSubmitting = ref(false)
const isSavingDraft = ref(false)
const showPreview = ref(false)
const newTag = ref('')

// 分类数据
const categories = ref([
  { id: '1', name: '行测' },
  { id: '2', name: '申论' },
  { id: '3', name: '面试' },
  { id: '4', name: '经验分享' },
  { id: '5', name: '资料分享' },
  { id: '6', name: '答疑解惑' }
])

// 推荐标签
const suggestedTags = ref([
  '行测', '申论', '面试', '备考经验', '真题解析', 
  '学习方法', '时间规划', '心态调整', '资料推荐'
])

// 热门话题
const trendingTopics = ref([
  '2024国考', '省考备考', '面试技巧', '申论写作', 
  '行测技巧', '资料分享', '经验交流'
])

// 获取分类图标
const getCategoryIcon = (name: string) => {
  const iconMap: Record<string, any> = {
    '行测': Reading,
    '申论': Edit,
    '面试': ChatDotSquare,
    '经验分享': Trophy,
    '资料分享': Document,
    '答疑解惑': QuestionFilled
  }
  return iconMap[name] || User
}

// 获取分类描述
const getCategoryDescription = (name: string) => {
  const descMap: Record<string, string> = {
    '行测': '行政职业能力测验相关讨论',
    '申论': '申论写作技巧和经验分享',
    '面试': '面试准备和技巧交流',
    '经验分享': '备考经验和心得分享',
    '资料分享': '学习资料和资源分享',
    '答疑解惑': '学习问题解答和讨论'
  }
  return descMap[name] || '相关讨论'
}

// 选择分类
const selectCategory = (categoryId: string) => {
  postForm.categoryId = categoryId
}

// 插入文本
const insertText = (before: string, after: string) => {
  const textarea = document.querySelector('.document-content-textarea textarea') as HTMLTextAreaElement
  if (textarea) {
    const start = textarea.selectionStart
    const end = textarea.selectionEnd
    const selectedText = postForm.content.substring(start, end)
    const newText = before + selectedText + after
    postForm.content = postForm.content.substring(0, start) + newText + postForm.content.substring(end)
    
    // 设置光标位置
    setTimeout(() => {
      textarea.focus()
      textarea.setSelectionRange(start + before.length, start + before.length + selectedText.length)
    }, 0)
  }
}

// 标题输入处理
const onTitleInput = () => {
  // 可以在这里添加实时保存草稿等功能
}

// 内容输入处理
const onContentInput = () => {
  // 可以在这里添加实时保存草稿等功能
}

// 添加标签
const addTag = () => {
  const tag = newTag.value.trim()
  if (tag && !postForm.tags.includes(tag)) {
    postForm.tags.push(tag)
    newTag.value = ''
  }
}

// 添加推荐标签
const addSuggestedTag = (tag: string) => {
  if (!postForm.tags.includes(tag)) {
    postForm.tags.push(tag)
  }
}

// 移除标签
const removeTag = (index: number) => {
  postForm.tags.splice(index, 1)
}

// 插入热门话题
const insertTopic = (topic: string) => {
  if (postForm.content) {
    postForm.content += ` #${topic}`
  } else {
    postForm.content = `#${topic} `
  }
}

// 获取分类名称
const getCategoryName = (categoryId: string) => {
  const category = categories.value.find(c => c.id === categoryId)
  return category?.name || '未分类'
}

// 格式化内容
const formatContent = (content: string) => {
  return content
    .replace(/\*\*(.*?)\*\*/g, '<strong>$1</strong>')
    .replace(/\*(.*?)\*/g, '<em>$1</em>')
    .replace(/`(.*?)`/g, '<code>$1</code>')
    .replace(/\n/g, '<br>')
}

// 保存草稿
const saveDraft = async () => {
  try {
    isSavingDraft.value = true
    // 这里可以调用保存草稿的API
    await new Promise(resolve => setTimeout(resolve, 1000))
    ElMessage.success('草稿保存成功')
  } catch (error) {
    ElMessage.error('保存草稿失败')
  } finally {
    isSavingDraft.value = false
  }
}

// 预览帖子
const previewPost = () => {
  if (!postForm.title || !postForm.content) {
    ElMessage.warning('请先填写标题和内容')
    return
  }
  showPreview.value = true
}

// 关闭预览
const closePreview = () => {
  showPreview.value = false
}

// 提交帖子
const submitPost = async () => {
  try {
    // 检查用户是否已登录
    if (!userStore.isAuthenticated) {
      ElMessage.error('请先登录后再发布帖子')
      router.push('/login')
      return
    }
    
    // 表单验证
    await postFormRef.value.validate()
    
    if (!postForm.categoryId) {
      ElMessage.warning('请选择帖子分类')
      return
    }
    
    isSubmitting.value = true
    
    // 调用API创建帖子
    const postData = {
      title: postForm.title,
      content: postForm.content,
      categoryId: parseInt(postForm.categoryId),
      tags: postForm.tags
    }
    
    console.log('发布帖子数据:', postData)
    console.log('用户认证状态:', userStore.isAuthenticated)
    console.log('Token:', localStorage.getItem('token'))
    
    await createPost(postData)
    
    ElMessage.success('帖子发布成功')
    
    // 延迟跳转，让用户看到成功消息
    setTimeout(() => {
      router.push('/forum')
    }, 1000)
    
  } catch (error: any) {
    console.error('发布帖子失败:', error)
    ElMessage.error(error.message || '发布失败，请重试')
  } finally {
    isSubmitting.value = false
  }
}

// 组件挂载
onMounted(() => {
  // 可以在这里加载用户草稿等
})
</script>

<style lang="scss" scoped>
.create-post-view {
  padding: 20px;
  max-width: 1200px;
  margin: 0 auto;
  min-height: 100vh;
}

.page-header {
  margin-bottom: 30px;
  
  .header-content {
    .breadcrumb {
      margin-bottom: 10px;
      font-size: 14px;
      color: #666;
      
      .breadcrumb-link {
        color: #409eff;
        text-decoration: none;
        
        &:hover {
          text-decoration: underline;
        }
      }
      
      .breadcrumb-separator {
        margin: 0 8px;
        color: #ccc;
      }
      
      .breadcrumb-current {
        color: #333;
      }
    }
    
    .page-title {
      font-size: 32px;
      font-weight: 700;
      color: #333;
      margin: 0 0 10px 0;
      background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
      -webkit-background-clip: text;
      -webkit-text-fill-color: transparent;
      background-clip: text;
    }
    
    .page-subtitle {
      font-size: 16px;
      color: #666;
      margin: 0;
    }
  }
}

.create-post-container {
  display: grid;
  grid-template-columns: 1fr 300px;
  gap: 30px;
  
  @media (max-width: 1200px) {
    grid-template-columns: 1fr;
    gap: 20px;
  }
}

.post-form-card {
  background: white;
  border-radius: 16px;
  padding: 0;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.08);
  border: 1px solid #f0f0f0;
  overflow: hidden;
  
  .form-header {
    margin-bottom: 0;
    padding: 40px 40px 20px;
    border-bottom: 2px solid #f8f9fa;
    
    .form-title {
      font-size: 24px;
      font-weight: 600;
      color: #333;
      margin: 0 0 10px 0;
      display: flex;
      align-items: center;
      gap: 10px;
      
      .el-icon {
        color: #409eff;
        font-size: 28px;
      }
    }
    
    .form-tips {
      display: flex;
      align-items: center;
      gap: 8px;
      color: #666;
      font-size: 14px;
      
      .el-icon {
        color: #409eff;
      }
    }
  }
}

.form-section {
  margin-bottom: 0;
  padding: 40px;
  
  .section-header {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 20px;
    
    .section-title {
      font-size: 18px;
      font-weight: 600;
      color: #333;
      margin: 0;
    }
    
    .required-mark {
      color: #f56c6c;
      font-size: 16px;
    }
    
    .optional-mark {
      color: #999;
      font-size: 14px;
    }
  }
}

.category-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 16px;
  
  .category-item {
    display: flex;
    align-items: center;
    gap: 16px;
    padding: 20px;
    border: 2px solid #f0f0f0;
    border-radius: 12px;
    cursor: pointer;
    transition: all 0.3s ease;
    background: white;
    
    &:hover {
      border-color: #409eff;
      box-shadow: 0 4px 12px rgba(64, 158, 255, 0.15);
      transform: translateY(-2px);
    }
    
    &.selected {
      border-color: #409eff;
      background: linear-gradient(135deg, #f0f8ff 0%, #e6f3ff 100%);
      box-shadow: 0 4px 12px rgba(64, 158, 255, 0.2);
    }
    
    .category-icon {
      width: 48px;
      height: 48px;
      border-radius: 12px;
      background: linear-gradient(135deg, #409eff 0%, #667eea 100%);
      display: flex;
      align-items: center;
      justify-content: center;
      color: white;
      font-size: 20px;
      flex-shrink: 0;
    }
    
    .category-info {
      flex: 1;
      
      .category-name {
        font-size: 16px;
        font-weight: 600;
        color: #333;
        margin: 0 0 4px 0;
      }
      
      .category-desc {
        font-size: 14px;
        color: #666;
        margin: 0;
        line-height: 1.4;
      }
    }
    
    .category-check {
      width: 24px;
      height: 24px;
      border-radius: 50%;
      background: #409eff;
      display: flex;
      align-items: center;
      justify-content: center;
      color: white;
      font-size: 16px;
    }
  }
}

// 文档编辑器样式
.document-editor {
  background: white;
  border-radius: 0;
  border: none;
  border-top: 1px solid #e1e5e9;
  box-shadow: none;
  overflow: hidden;
  
  .editor-toolbar {
    display: flex;
    align-items: center;
    gap: 16px;
    padding: 12px 32px;
    background: #f8f9fa;
    border-bottom: 1px solid #e1e5e9;
    
    .toolbar-group {
      display: flex;
      align-items: center;
      gap: 4px;
      
      .el-button {
        border: 1px solid #d0d7de;
        background: white;
        color: #656d76;
        
        &:hover {
          background: #f6f8fa;
          border-color: #d0d7de;
          color: #0969da;
        }
        
        &:active {
          background: #f3f4f6;
        }
      }
    }
  }
  
  .editor-content-wrapper {
    .title-form-item {
      margin: 0;
      padding: 24px 32px 8px;
      
      .document-title-input {
        :deep(.el-input__inner) {
          font-size: 20px;
          font-weight: 600;
          color: #1a1a1a;
          padding: 12px 0;
          border: none;
          border-bottom: 1px solid #e1e5e9;
          border-radius: 0;
          background: transparent;
          box-shadow: none;
          
          &:focus {
            border-bottom-color: #409eff;
            box-shadow: none;
          }
          
          &::placeholder {
            color: #8e8e8e;
            font-weight: 400;
            font-size: 20px;
          }
        }
      }
    }
    
    .content-form-item {
      margin: 0;
      
      .document-content-textarea {
        :deep(.el-textarea__inner) {
          border: none;
          border-radius: 0;
          font-size: 16px;
          line-height: 1.7;
          padding: 16px 32px 32px;
          resize: vertical;
          min-height: 600px;
          background: white;
          color: #1a1a1a;
          font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Noto Sans', Helvetica, Arial, sans-serif;
          
          &:focus {
            box-shadow: none;
            border: none;
          }
          
          &::placeholder {
            color: #8e8e8e;
            font-style: italic;
            font-size: 16px;
          }
        }
      }
    }
    
    .editor-footer {
      display: flex;
      justify-content: space-between;
      align-items: center;
      padding: 16px 32px;
      background: #f8f9fa;
      border-top: 1px solid #e1e5e9;
      
      .char-count {
        color: #656d76;
        font-size: 13px;
        font-weight: 500;
      }
      
      .editor-tips {
        display: flex;
        align-items: center;
        gap: 6px;
        color: #656d76;
        font-size: 13px;
        
        .el-icon {
          color: #409eff;
        }
      }
    }
  }
}

// 保留原有的其他样式
.title-input {
  :deep(.el-input__inner) {
    font-size: 16px;
    padding: 16px 20px;
    border-radius: 8px;
    border: 2px solid #f0f0f0;
    
    &:focus {
      border-color: #409eff;
    }
  }
}

.input-tips {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 8px;
  color: #666;
  font-size: 14px;
  
  .el-icon {
    color: #409eff;
  }
}

.tags-container {
  .tag-input {
    display: flex;
    gap: 12px;
    margin-bottom: 16px;
    
    .tag-input-field {
      flex: 1;
    }
  }
  
  .tag-suggestions {
    margin-bottom: 16px;
    
    .suggestion-label {
      color: #666;
      font-size: 14px;
      margin-right: 12px;
    }
    
    .suggestion-tag {
      margin-right: 8px;
      margin-bottom: 8px;
      cursor: pointer;
      transition: all 0.2s;
      
      &:hover {
        background: #409eff;
        color: white;
      }
    }
  }
  
  .selected-tags {
    .selected-tag {
      margin-right: 8px;
      margin-bottom: 8px;
    }
  }
}

.publish-settings {
  display: flex;
  flex-wrap: wrap;
  gap: 24px;
  
  .setting-item {
    color: #666;
  }
}

.form-actions {
  padding: 40px;
  border-top: 1px solid #e1e5e9;
  background: #fafbfc;
  
  .action-buttons {
    display: flex;
    gap: 16px;
    margin-bottom: 16px;
    
    .submit-btn {
      background: linear-gradient(135deg, #409eff 0%, #667eea 100%);
      border: none;
      
      &:hover {
        background: linear-gradient(135deg, #337ecc 0%, #5a6fd8 100%);
      }
    }
  }
  
  .action-tips {
    display: flex;
    align-items: center;
    gap: 8px;
    color: #666;
    font-size: 14px;
    
    .el-icon {
      color: #409eff;
    }
  }
}

.help-sidebar {
  .help-card {
    background: white;
    border-radius: 12px;
    padding: 24px;
    margin-bottom: 20px;
    box-shadow: 0 2px 12px rgba(0, 0, 0, 0.08);
    border: 1px solid #f0f0f0;
    
    .help-title {
      font-size: 16px;
      font-weight: 600;
      color: #333;
      margin: 0 0 16px 0;
      display: flex;
      align-items: center;
      gap: 8px;
      
      .el-icon {
        color: #409eff;
      }
    }
    
    .help-content {
      .help-item {
        margin-bottom: 20px;
        
        &:last-child {
          margin-bottom: 0;
        }
        
        h4 {
          font-size: 14px;
          font-weight: 600;
          color: #333;
          margin: 0 0 8px 0;
        }
        
        ul {
          margin: 0;
          padding-left: 16px;
          
          li {
            font-size: 13px;
            color: #666;
            line-height: 1.5;
            margin-bottom: 4px;
          }
        }
      }
    }
    
    .trending-topics {
      .topic-tag {
        margin-right: 8px;
        margin-bottom: 8px;
        cursor: pointer;
        transition: all 0.2s;
        
        &:hover {
          background: #409eff;
          color: white;
        }
      }
    }
  }
}

.preview-content {
  .preview-title {
    font-size: 24px;
    font-weight: 600;
    color: #333;
    margin: 0 0 16px 0;
  }
  
  .preview-meta {
    display: flex;
    align-items: center;
    gap: 16px;
    margin-bottom: 20px;
    padding-bottom: 16px;
    border-bottom: 1px solid #f0f0f0;
    
    .preview-category {
      color: #409eff;
      font-weight: 500;
    }
    
    .preview-tags {
      .el-tag {
        margin-right: 8px;
      }
    }
  }
  
  .preview-body {
    font-size: 14px;
    line-height: 1.6;
    color: #333;
    
    :deep(strong) {
      font-weight: 600;
    }
    
    :deep(em) {
      font-style: italic;
    }
    
    :deep(code) {
      background: #f5f5f5;
      padding: 2px 4px;
      border-radius: 4px;
      font-family: 'Courier New', monospace;
    }
  }
}

@media (max-width: 768px) {
  .create-post-view {
    padding: 15px;
  }
  
  .post-form-card {
    padding: 0;
  }
  
  .category-grid {
    grid-template-columns: 1fr;
  }
  
  .form-actions .action-buttons {
    flex-direction: column;
  }
  
  .document-editor {
    .editor-toolbar {
      padding: 8px 16px;
      flex-wrap: wrap;
      gap: 8px;
    }
    
    .editor-content-wrapper {
      .title-form-item {
        padding: 16px 16px 8px;
        
        .document-title-input {
          :deep(.el-input__inner) {
            font-size: 18px;
            padding: 8px 0;
          }
          
          &::placeholder {
            font-size: 18px;
          }
        }
      }
      
      .content-form-item {
        .document-content-textarea {
          :deep(.el-textarea__inner) {
            padding: 8px 16px 16px;
            font-size: 16px;
            min-height: 400px;
          }
          
          &::placeholder {
            font-size: 16px;
          }
        }
      }
      
      .editor-footer {
        padding: 12px 16px;
        flex-direction: column;
        gap: 8px;
        align-items: flex-start;
      }
    }
  }
  
  .form-section {
    padding: 20px;
  }
  
  .form-actions {
    padding: 20px;
  }
}
</style>
